// Magic Software, Inc.
// http://www.magic-software.com
// Copyright (c) 2000, All Rights Reserved
//
// Source code from Magic Software is supplied under the terms of a license
// agreement and may not be copied or disclosed except in accordance with the
// terms of that agreement.  The various license agreements may be found at
// the Magic Software web site.  This file is subject to the license
//
// RESTRICTED USE SOURCE CODE
// http://www.magic-software.com/License/restricted.pdf

#include "MgcTexture.h"

MgcImplementRTTI(MgcTexture,MgcObject);
MgcImplementStream(MgcTexture);

//----------------------------------------------------------------------------
MgcTexture::MgcTexture ()
{
    m_eCorrection = CM_PERSPECTIVE;
    m_eApply = AM_REPLACE;
    m_kBlendColor = MgcColor::BLACK;
    m_eWrap = WM_CLAMP_S_CLAMP_T;
    m_eFilter = FM_NEAREST;
    m_eMipmap = MM_NONE;
    m_fPriority = 1.0;
    m_uiUserData = 0;
}
//----------------------------------------------------------------------------
MgcTexture::~MgcTexture ()
{
    m_spkImage = 0;
}
//----------------------------------------------------------------------------

//---------------------------------------------------------------------------
// streaming
//---------------------------------------------------------------------------
MgcObject* MgcTexture::Factory (MgcStream& rkStream)
{
    MgcTexture* pkObject = new MgcTexture;
    MgcStream::Link* pkLink = new MgcStream::Link(pkObject);
    pkObject->Load(rkStream,pkLink);
    return pkObject;
}
//---------------------------------------------------------------------------
void MgcTexture::Load (MgcStream& rkStream, MgcStream::Link* pkLink)
{
    MgcObject::Load(rkStream,pkLink);

    // native data
    MgcStreamRead(rkStream,m_eCorrection);
    MgcStreamRead(rkStream,m_eApply);
    MgcStreamRead(rkStream,m_kBlendColor);
    MgcStreamRead(rkStream,m_eWrap);
    MgcStreamRead(rkStream,m_eFilter);
    MgcStreamRead(rkStream,m_eMipmap);
    MgcStreamRead(rkStream,m_fPriority);

    // link data
    MgcImage* pkImage;
    MgcStreamRead(rkStream,pkImage);
    pkLink->Add(pkImage);
}
//---------------------------------------------------------------------------
void MgcTexture::Link (MgcStream& rkStream, MgcStream::Link* pkLink)
{
    MgcObject::Link(rkStream,pkLink);

    MgcObject* pkLinkID = pkLink->GetLinkID();
    m_spkImage = (MgcImage*)rkStream.GetFromMap(pkLinkID);
}
//---------------------------------------------------------------------------
bool MgcTexture::Register (MgcStream& rkStream)
{
    if ( !MgcObject::Register(rkStream) )
        return false;

    if ( m_spkImage )
        m_spkImage->Register(rkStream);

    return true;
}
//---------------------------------------------------------------------------
void MgcTexture::Save (MgcStream& rkStream)
{
    MgcObject::Save(rkStream);

    // native data
    MgcStreamWrite(rkStream,m_eCorrection);
    MgcStreamWrite(rkStream,m_eApply);
    MgcStreamWrite(rkStream,m_kBlendColor);
    MgcStreamWrite(rkStream,m_eWrap);
    MgcStreamWrite(rkStream,m_eFilter);
    MgcStreamWrite(rkStream,m_eMipmap);
    MgcStreamWrite(rkStream,m_fPriority);

    // m_uiUserData is derived, no need to save

    // link data
    MgcStreamWrite(rkStream,m_spkImage);
}
//---------------------------------------------------------------------------
